package org.mozhu.mboot.core.social;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionSignUp;
import org.springframework.stereotype.Component;

@Component
public class CustomConnectionSignUp implements ConnectionSignUp {

    public String execute(Connection<?> connection) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }
        User userDetails = (User) authentication.getDetails();
        return userDetails.getUsername();
    }
}
